import {
  listClasses,
  getClasses,
  classeslistCollege,
  classeslistMajor,
  delClasses,
  addClasses,
  updateClasses,
  exportClasses,
} from "@/api/org/classes";
import { listMajor } from "@/api/org/major";
// import { listTerm } from "@/api/org/term";
import { listCollege } from "@/api/org/college";
// import { listSchoolyear } from "@/api/org/schoolyear";

// 组织结构中共用的方法
export const org = {
  data() {
    return {
      //学年信息
      // yearOptions: [],
      //  // 学期
      //  termNameOptions: [
      //   {
      //     termId: "",
      //     termName: "",
      //   },
      // ],
        //学院信息
      collegeOptions: [
        {
          id: "",
          name: "",
        },
      ],
        //专业信息
        majorOptions: [
          {
            id: "",
            name: "",
          },
        ],

    }
  },
  methods: {
    // resetTermOptions() {
    //   this.termNameOptions = [
    //     {
    //       termId: "",
    //       termName: "",
    //     },
    //   ];

    // },
    // resetCollegeOptions() {
    //   this.collegeOptions = [
    //     {
    //       id: "",
    //       name: "",
    //     },
    //   ];
    // },
    resetMajorOptions() {
      this.majorOptions = [
        {
          id: "",
          name: "",
        },
      ];
    },


    // // 获取学年列表
    // getYearList() {
    //   listSchoolyear().then(response => {
    //     this.yearOptions = response.rows
    //     console.log("yearOptions: ", this.yearOptions);
    //   });
    // },
    //  // 搜索栏 通过学期搜索学院
    //  searchCollegeByTerm() {
    //   this.queryParams.collegeId = "";
    //    this.queryParams.majorId = "";
    //    this.resetCollegeOptions();
    //    this.resetMajorOptions();
    //   if (this.queryParams.classesId!=null) {
    //     this.queryParams.classesId = "";
    //     this.resetClassOptions();
    //   }
    //   if (this.queryParams.termId !== '') {
    //      listCollege({
    //        termId: this.queryParams.termId,
    //      }).then((res) => {
    //        this.collegeOptions = res.rows;
    //      });
    //    }
    // },
     // 当el-select的值改变时触发验证
     handleChange(refName,valid){
      this.$refs[refName].validateField(valid);
    },

    getCollegeList() {
      listCollege().then(response => {
        this.collegeOptions = response.rows
        console.log("collegeOptions: ", this.collegeOptions);
      });
    },
      // 搜索栏 通过学院搜索专业
    searchMajorByCollege() {
      this.queryParams.majorId = "";
      this.resetMajorOptions();
      if (this.queryParams.classesId!=null) {
        this.queryParams.classesId = "";
        this.resetClassOptions();
      }
      if (this.queryParams.collegeId !== '') {
        listMajor({
          collegeId: this.queryParams.collegeId,
        }).then((res) => {
          this.majorOptions = res.rows;
        });
      }
    },

    //   // 添加 通过学期搜索学院
    // addCollegeByTerm() {
    //   this.form.collegeId = "";
    //   this.form.majorId = "";

    //   this.resetCollegeOptions();
    //   this.resetMajorOptions();
    //   if (this.form.classesId != null) {
    //     this.form.classesId = "";
    //     this.resetClassOptions();
    //   }
    //   if (this.form.termId !== '') {
    //     listCollege({
    //       termId: this.form.termId,
    //     }).then((res) => {
    //       this.collegeOptions = res.rows;
    //     });
    //   }
    // },
     // 添加 通过学院搜索专业
     addMajorByCollege() {
       this.form.majorId = "";
       this.resetMajorOptions();
       if (this.form.classesId != null) {
        this.form.classesId = "";
        this.resetClassOptions();
       }
       if (this.form.collegeId !== '') {
         listMajor({
           collegeId: this.form.collegeId,
         }).then((res) => {
           this.majorOptions = res.rows;
         });
       }
    },


  },
  computed: {

  },

}
